<?php
namespace app\common\model;

use think\Model;

class Agents extends Model
{
    protected $pk = 'age_id';
    protected $type = [
        'age_create_time'  =>  'timestamp:Y/m/d H:i:s',
        'age_login_time' => 'timestamp',
    ];

    /*
     * @name 指定代理商id获取代理商名称
     * @author Jin
     * @date 2017.12.21
     * @param $id int 代理商id
     * @return string 代理商名称
     **/
    public function getNameByAgentId($id = '')
    {
        return Agents::where('age_id', $id)->value('age_username');
    }

    public function getAgeStatusAttr($value){
        $arr = ['0'=>'禁用',1=>'启用'];
        return $arr[$value];
    }

    /**
     * 关联权限表
     * @return $this
     */
    public function role(){
        return $this->belongsTo('Roles','age_role','role_id')->field('role_id,role_name,role_auth_id');
    }

    /**
     * 关联代理信息表
     */
    public function manage(){
        return $this->belongsTo('AgentManage','age_agent_manage','agem_id','agem_number');
    }

}
